<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户编号" prop="no">
        <el-input
          v-model="queryParams.no"
          placeholder="请输入商户编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户名称" prop="cnName">
        <el-input
          v-model="queryParams.cnName"
          placeholder="请输入商户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="协议编号" prop="meanNo">
        <el-input
          v-model="queryParams.meanNo"
          placeholder="请输入协议编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="examineResult">
        <el-select v-model="queryParams.examineResult" placeholder="请选择商户类型" clearable>
          <el-option
          v-for="dict in mbiExamineResultType"
          :key="dict.dictValue"
          :label="dict.dictLabel"
          :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link :to="{name:'merchantBasicEdit',params:{type:1}}">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            v-hasPermi="['merchant:basic:add']"
          >新增</el-button>
        </router-link>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['merchant:basic:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['merchant:basic:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="basicList" @selection-change="handleSelectionChange" :border="true">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户编号" align="center" prop="no" />
      <el-table-column label="商户名称" align="center" prop="cnName" />
      <el-table-column label="商户类型" align="center" prop="type" :formatter="mctTypeFmt"/>
      <el-table-column label="主营产品" align="center" prop="mainProduct" />
      <el-table-column label="商户状态" align="center" prop="status" :formatter="mctStatusFmt"/>
      <el-table-column label="官网" align="center" prop="url" />
      <el-table-column label="协议编号" align="center" prop="meanNo" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link :to="{name:'merchantBasicView',params:{type:2,no:scope.row.no}}">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-hasPermi="['merchant:basic:query']"
            >详情</el-button>
          </router-link>
          <router-link :to="{name:'merchantBasicEdit',params:{type:2,no:scope.row.no}}">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-hasPermi="['merchant:basic:edit']"
            >修改</el-button>
          </router-link>
          <router-link :to="{name:'merchantBasicView',params:{type:4,no:scope.row.no}}">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-hasPermi="['merchant:basic:audit']"
              v-if="scope.row.progressBitmap == '1111' && scope.row.examineResult == 0"
            >审核</el-button>
          </router-link>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['merchant:basic:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBasic, getBasic, delBasic, delBasicByNos, addBasic, updateBasic, exportBasic, listAndProgressBitmap } from "@/api/merchant/basic";
import { getToken } from "@/utils/auth";

export default {
  name: "Basic",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中数组
      nos: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户信息表格数据
      basicList: [],
      //商户类型
      mbiType: [],
      //商户状态
      mbiStatus: [],
      //商户来源类型
      mbiSourceType: [],
      //审核状态类型
      mbiExamineResultType: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        no: null,
        cnName: null,
        shortName: null,
        enName: null,
        type: null,
        mainProduct: null,
        status: null,
        logo: null,
        url: null,
        meanNo: null,
        businessDataNo: null,
        hygienicDataNo: null,
        foodSafetyDataNo: null,
        healthDataNo: null,
        accountOpeningDataNo: null,
        settledStartDate: null,
        settledEndDate: null,
        examineCode: null,
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null,
        progressBitmap: null,
        examineResult: null
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("mct_merchant_type").then(response => {
      this.mbiType = response.data;
    });
    this.getDicts("mct_merchant_status").then(response => {
      this.mbiStatus = response.data;
    });
    this.getDicts("mct_merchant_source_type").then(response => {
      this.mbiSourceType = response.data;
    });
    this.getDicts("msg_message_template_examineResult_type").then(response => {
      this.mbiExamineResultType = response.data;
    });
  },
  methods: {
    /** 查询商户信息列表 */
    getList() {
      this.loading = true;
      listAndProgressBitmap(this.queryParams).then(response => {
        this.basicList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.nos = selection.map(item => item.no)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const nos = row.no || this.nos;
      this.$confirm('是否确认删除商户信息编号为"' + nos + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBasicByNos(nos);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有商户信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportBasic(queryParams);
        }).catch(() => {});
    },
    /** 商户状态格式化 */
    mctStatusFmt(row, column) {
      var val = row.status;
      this.mbiStatus.forEach(element => {
        if(val == element.dictValue){
          val = element.dictLabel;
        }
      });
      return val;
    },
    /** 商户类型格式化 */
    mctTypeFmt(row, column) {
      var val = row.type.trim();
      this.mbiType.forEach(element => {
        if(val == element.dictValue){
          val = element.dictLabel;
        }
      });
      return val;
    }
  }
};
</script>
